{include file="public/header"/}
<div class="main-body">
	<table class="layui-table" lay-even lay-skin="line">
		<colgroup>
			<col width="150">
			<col width="200">
			<col>
		</colgroup>
		<thead>
		<tr class="table_head_background">
			<th width="3%">uid</th>
			<th width="3%">头像</th>
			<th width="5%">登录名</th>
			<th width="10%">昵称</th>
			<th width="15%">注册时间</th>
			<th width="15%">操作</th>
		</tr>
		</thead>
		<tbody>
		{volist name='users' id='item'}
		<tr>
			<td>{$item.uid}</td>
			<td><img src="{$item.avatar}" width="40px"/></td>
			<td>{$item.username}</td>
			<td>{$item.nickname}</td>
			<td>{$item.timestamp|date="Y-m-d H:i:s",###}</td>
			<td uid="{$item.uid}">
				<button class="layui-btn layui-btn-sm" pop-event="edit_user">编辑</button>
				<button class="layui-btn layui-btn-sm" pop-event="message_log">聊天日志</button>
				{if $item.account_state=='disabled'}
				    <button class="layui-btn layui-btn-sm layui-btn-warm" pop-event="enable_user">启用</button>
				{else}
				    <button class="layui-btn layui-btn-sm layui-btn-danger" pop-event="disable_user">禁用</button>
				{/if}
			</td>
		</tr>
		{/volist}
		</tbody>
	</table>

	<div id="page"></div>


	<script>
        layui.use(['laypage', 'layer'], function() {
            var laypage = layui.laypage;
            laypage.render({
                elem: 'page'
				, limit: {$step}
                , count: {$count} //数据总数，从服务端得到
				, curr: {$page}
                , jump: function (obj, first) {
                    //首次不执行
                    if (!first) {
                        //do something
                        location = '/admin/user/index?page='+obj.curr;
                    }
                }
            });

            $('.main-body').on("click", "*[pop-event]", function (e) {
                var event = $(this).attr('pop-event');
                callback[event]($(e.target.parentNode).attr('uid'));
            });

            var callback = {
                edit_user: function (uid) {
                    layer.open({
                        type: 2,
                        title: '编辑用户信息',
                        content: '/admin/user/edit?uid=' + uid,
                        area: ['800px', '550px']
                    });
                },
                message_log:function (uid) {
                    layer.open({
                        type: 2,
						title: '聊天日志',
                        content: '/admin/user/chatlog?uid=' + uid,
                        area: ['800px', '550px']
                    });
                },
                enable_user:function (uid) {
                    $.ajax({
                        url:'/admin/user/update',
                        type:'post',
                        data: {uid:uid, account_state:'normal'},
                        success:function(res){
                            if (res.code == 0) {
                                layui.layer.msg('操作成功');
                                setTimeout(function(){location.reload();}, 1000);
                            } else {
                                layui.layer.msg(res.msg);
                            }
                        }
                    });
                },
                disable_user:function (uid) {
                    layer.confirm('确定禁用该用户么？', {icon: 3, title:'提示'}, function(index) {
                        $.ajax({
                            url: '/admin/user/update',
                            type: 'post',
                            data: {uid: uid, account_state: 'disabled'},
                            success: function (res) {
                                if (res.code == 0) {
                                    layui.layer.msg('操作成功');
                                    setTimeout(function () {
                                        location.reload();
                                    }, 1000);
                                } else {
                                    layui.layer.msg(res.msg);
                                }
                            }
                        });
                    });
                }
            }
        });

	</script>
</div>

{include file="public/footer"/}


